package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing")
@Api(tags = "护理计划")
public class NursingPlanController {
    @Autowired
    NursingPlanService nursingPlanService;

    @GetMapping("/plan")
    @ApiOperation("查询所有护理计划")
    public ResponseResult query() {
        List<NursingPlanVo> nursingPlanList = nursingPlanService.query();
        return ResponseResult.success(nursingPlanList);
    }

    @PostMapping("/plan")
    @ApiOperation("新增计划")
    public ResponseResult add(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.add(nursingPlanDto);
        return ResponseResult.success();
    }

    @GetMapping("/plan/search")
    @ApiOperation("条件分页查询")
    public ResponseResult<PageResponse<NursingPlanVo>> search(String name, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, Integer status) {
        PageResponse<NursingPlanVo> result = nursingPlanService.search(name, pageNum, pageSize, status);
        return ResponseResult.success(result);
    }

    @GetMapping("/plan/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult<NursingPlanVo> getById(@PathVariable Long id) {
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return ResponseResult.success(nursingPlanVo);
    }

    @PutMapping("/plan/{id}")
    @ApiOperation("修改")
    public ResponseResult update(@PathVariable Long id, @RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.update(nursingPlanDto);
        return ResponseResult.success();
    }
    @DeleteMapping("/plan/{id}")
    @ApiOperation("删除计划")
    public ResponseResult delete(@PathVariable Long id){
        nursingPlanService.delete(id);
        return ResponseResult.success();
    }
    @PutMapping("/plan/{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult statusAlter(@PathVariable Long id,@PathVariable Integer status){
        nursingPlanService.statusAlter(id,status);
        return ResponseResult.success();
    }
}
